package com.nd.mobile.study.domain;

import java.io.Serializable;
import java.lang.reflect.Type;

import android.os.Bundle;

import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.fuckhtc.gson.reflect.TypeToken;
import com.nd.mobile.study.common.config.Commands;
import com.nd.mobile.study.common.config.ReqParam;
import com.nd.mobile.study.common.util.HttpRequestUtil;

public class MaterialInfo implements Serializable{
	
	private static final long	serialVersionUID	= 1L;

	@SerializedName("SLFID")
	private String id;
	
	@SerializedName("FileTitle")
	private String name;

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}
	
	public MaterialInfoDetail getDetail(User user) throws Exception {
		Bundle data = new Bundle();
		data.putString(ReqParam.COMMON_USER_ID, user.getUserId());
		data.putString(ReqParam.MATERIAL_ID, id);
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_MATERIAL_DETAIL, data);
		Gson gson = new Gson();
		Type type = new TypeToken<Result<MaterialInfoDetail[]>>(){}.getType();
		Result<MaterialInfoDetail[]> result = gson.fromJson(jsonData, type);
		MaterialInfoDetail body = result.getBody()[0];
		return body;
	}
}
